<?php

/**
 * Article filter form base class.
 *
 * @package    SdCommerce
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseArticleFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'id_categorie'           => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Categorie'), 'add_empty' => true)),
      'id_unite'               => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Unite'), 'add_empty' => true)),
      'id_tva'                 => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Tva'), 'add_empty' => true)),
      'reference'              => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'code_barre'             => new sfWidgetFormFilterInput(),
      'designation'            => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'description'            => new sfWidgetFormFilterInput(),
      'caracteristique'        => new sfWidgetFormFilterInput(),
      'prix_uv_ht'             => new sfWidgetFormFilterInput(),
      'prix_uv_ttc'            => new sfWidgetFormFilterInput(),
      'marge'                  => new sfWidgetFormFilterInput(),
      'marge_pourcent'         => new sfWidgetFormFilterInput(),
      'prix_ua_ht'             => new sfWidgetFormFilterInput(),
      'prix_ua_ttc'            => new sfWidgetFormFilterInput(),
      'mont_rem_max'           => new sfWidgetFormFilterInput(),
      'taux_rem_max'           => new sfWidgetFormFilterInput(),
      'inactif'                => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'service'                => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'cout_revient'           => new sfWidgetFormFilterInput(),
      'frai_art'               => new sfWidgetFormFilterInput(),
      'created_at'             => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'             => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'm_fournisseur_list'     => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Fournisseur')),
      'm_departement_list'     => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Departement')),
      'categories_remise_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'CategorieRemise')),
      'tarifs_list'            => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Tarif')),
      'uniteslogistique_list'  => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'UniteLogistique')),
    ));

    $this->setValidators(array(
      'id_categorie'           => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Categorie'), 'column' => 'id')),
      'id_unite'               => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Unite'), 'column' => 'id')),
      'id_tva'                 => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Tva'), 'column' => 'id')),
      'reference'              => new sfValidatorPass(array('required' => false)),
      'code_barre'             => new sfValidatorPass(array('required' => false)),
      'designation'            => new sfValidatorPass(array('required' => false)),
      'description'            => new sfValidatorPass(array('required' => false)),
      'caracteristique'        => new sfValidatorPass(array('required' => false)),
      'prix_uv_ht'             => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'prix_uv_ttc'            => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'marge'                  => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'marge_pourcent'         => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'prix_ua_ht'             => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'prix_ua_ttc'            => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'mont_rem_max'           => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'taux_rem_max'           => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'inactif'                => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'service'                => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'cout_revient'           => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'frai_art'               => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'created_at'             => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'             => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'm_fournisseur_list'     => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Fournisseur', 'required' => false)),
      'm_departement_list'     => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Departement', 'required' => false)),
      'categories_remise_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'CategorieRemise', 'required' => false)),
      'tarifs_list'            => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Tarif', 'required' => false)),
      'uniteslogistique_list'  => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'UniteLogistique', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('article_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addMFournisseurListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.ArticleFournisseur ArticleFournisseur')
      ->andWhereIn('ArticleFournisseur.fournisseur_id', $values)
    ;
  }

  public function addMDepartementListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.StockArticle StockArticle')
      ->andWhereIn('StockArticle.departement_id', $values)
    ;
  }

  public function addCategoriesRemiseListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.CategorieRemiseArticle CategorieRemiseArticle')
      ->andWhereIn('CategorieRemiseArticle.id_article', $values)
    ;
  }

  public function addTarifsListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.TarifArticle TarifArticle')
      ->andWhereIn('TarifArticle.id_tarif', $values)
    ;
  }

  public function addUniteslogistiqueListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.ArticleUniteLogistique ArticleUniteLogistique')
      ->andWhereIn('ArticleUniteLogistique.id_unite_logistique', $values)
    ;
  }

  public function getModelName()
  {
    return 'Article';
  }

  public function getFields()
  {
    return array(
      'id'                     => 'Number',
      'id_categorie'           => 'ForeignKey',
      'id_unite'               => 'ForeignKey',
      'id_tva'                 => 'ForeignKey',
      'reference'              => 'Text',
      'code_barre'             => 'Text',
      'designation'            => 'Text',
      'description'            => 'Text',
      'caracteristique'        => 'Text',
      'prix_uv_ht'             => 'Number',
      'prix_uv_ttc'            => 'Number',
      'marge'                  => 'Number',
      'marge_pourcent'         => 'Number',
      'prix_ua_ht'             => 'Number',
      'prix_ua_ttc'            => 'Number',
      'mont_rem_max'           => 'Number',
      'taux_rem_max'           => 'Number',
      'inactif'                => 'Boolean',
      'service'                => 'Boolean',
      'cout_revient'           => 'Number',
      'frai_art'               => 'Number',
      'created_at'             => 'Date',
      'updated_at'             => 'Date',
      'm_fournisseur_list'     => 'ManyKey',
      'm_departement_list'     => 'ManyKey',
      'categories_remise_list' => 'ManyKey',
      'tarifs_list'            => 'ManyKey',
      'uniteslogistique_list'  => 'ManyKey',
    );
  }
}
